package com.example.mybatisplus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.model.domain.BatchSetting;
import com.example.mybatisplus.mapper.BatchSettingMapper;
import com.example.mybatisplus.model.dto.PageDTO;
import com.example.mybatisplus.service.BatchSettingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 批次设定 服务实现类
 * </p>
 *
 * @author sharplu
 * @since 2023-07-10
 */
@Service
public class BatchSettingServiceImpl extends ServiceImpl<BatchSettingMapper, BatchSetting> implements BatchSettingService {
    @Override
    public Page<BatchSetting> pageList(PageDTO pageDTO, BatchSetting batchSetting) {
        QueryWrapper<BatchSetting> wrapper = new QueryWrapper<>();
        if(batchSetting.getId()!=null){
            wrapper.eq("id",batchSetting.getId());
        }
        if(StringUtils.isNotBlank(batchSetting.getName())){
            wrapper.like("NAME",batchSetting.getName());
        }
        if (StringUtils.isNotBlank(batchSetting.getDifficultyLevel())){
            wrapper.like("difficultyLevel", batchSetting.getDifficultyLevel());
        }
        if (batchSetting.getActive() != null){
            wrapper.eq("active", batchSetting.getActive());
        }
        Page<BatchSetting> page = new Page<>(pageDTO.getPageNo(),pageDTO.getPageSize());
        baseMapper.selectPage(page, null);
        return page;
    }
}
